# -*- coding: utf-8 -*-
# Author: xiantingDeng
# Email: dengxianting@shxgroup.net
# Time: 2020/8/6 17:55



from common.utils.api_info import get_apk_info
from common.utils.device_util import get_device
from common.utils.file_util import get_real_data_dir
from common.utils.read_util import OperationYaml


devices, version = get_device()
current_env, apk_path, apkVersion, appPackage, appActivity = get_apk_info()

host = "http://127.0.0.1:4723/wd/hub"

appium_config = {
    "platformName": "Android",
    "platformVersion": version,
    "deviceName": devices,
    # "udid": "127.0.0.1:21503",
    "noReset": "false",
    "unicodeKeyboard": "true",
    "resetKeyboard": "true",
    "app": apk_path,
    "appPackage": appPackage,
    "appActivity": appActivity,
    "autoGrantPermissions": "true"
}


def piece_together_element(file):
    '''
    根据env.ini文件配置的环境更改yaml中的元素
    :return: 返回添加好的元素 dict
    '''

    dict = {}
    id = "locator"
    files = get_real_data_dir("{}.yaml".format(file))
    data = OperationYaml(files)[file]["locators"]
    app_package = appPackage
    for i in data:
        element_dicts = {}
        for key, value in i.items():
            s = str(value)
            if id in s:
                values = s.replace(id, app_package)
                element_dicts[key] = values
            else:
                element_dicts[key] = value
        dict.setdefault(i["name"], element_dicts)
    return dict
